<?php

declare(strict_types=1);

use App\Environment;

require_once dirname(__DIR__) . '/vendor/autoload.php';

if (isAppEnvEmpty()) {
    putenv('APP_ENV=' . Environment::DEV);
    $_ENV['APP_ENV'] = Environment::DEV;
    $_SERVER['APP_ENV'] = Environment::DEV;
}

Environment::prepare();

/**
 * Determine whether the APP_ENV variable is unset or empty in any source.
 */
function isAppEnvEmpty(): bool
{
    $sources = [
        getenv('APP_ENV', true),
        getenv('APP_ENV'),
        $_ENV['APP_ENV'] ?? null,
        $_SERVER['APP_ENV'] ?? null,
    ];

    foreach ($sources as $value) {
        if ($value !== false && $value !== null && $value !== '') {
            return false;
        }
    }

    return true;
}
